﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using kunukn.RecommendationEngine.AreaRecommendation.Code.Constants;
using kunukn.RecommendationEngine.AreaRecommendation.Code.Engine;
using kunukn.RecommendationEngine.AreaRecommendation.Code.Entities;

namespace kunukn.RecommendationEngine.AreaRecommendation.Code.Helpers
{
    /// <summary>
    /// Author: Kunuk Nykjaer
    /// </summary>
    public static class ItemHelper
    {
       
        public static bool IsValid(this Item item)
        {
            return item == null ? false : IsValidaItemName(item.Name);            
        }
        public static bool IsValidaItemName(this string name)
        {
            return SessionHelper.GetLookupNameToIndex().ContainsKey(name);
        }


        public static string HtmlEncode(this string name)
        {
            return System.Web.HttpUtility.HtmlEncode(name);
        }
               
        public static void TrackItemEvent(Item item)
        {
            if (!item.IsValid())
            {
                // Real life scenario do also Track invalid item event
                return;
            }

            // This order is important
            SessionHelper.GetItem2Item().AddViewed(item);
            SessionHelper.GetViewedItems().Add(item);
        }

        
    }
}